package cn.edu.scau.cmi.xiehaizhou.client;

import cn.edu.scau.cmi.xiehaizhou.singleton.Chairman;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class ChairmanCilent extends Application{
	@Override
	public void start(Stage primaryStage)
	{
		primaryStage.setTitle("单例模式");
		
		GridPane pane = new GridPane();
		pane.setAlignment(Pos.CENTER);
		pane.setPadding(new Insets(10,10,10,10));
		pane.add(new Label("姓名："), 0, 0);
		TextField txtf = new TextField();
		pane.add(txtf, 1, 0);
		Button btn = new Button("创建/获得“主席”对象");
		pane.add(btn, 1, 1);
		//绑定事件
		btn.setOnAction(e -> 
		{
			Chairman chairman = Chairman.getInstance(txtf.getText().trim());
			String inf = "中华人民共和国第一任主席是：" + chairman.getName() + "同志\n" ;
			inf += "对象：" + Chairman.getInstance(txtf.getText().trim());
			Alert information = new Alert(Alert.AlertType.INFORMATION,inf);
			information.setHeaderText(null);
			information.showAndWait();
		}
		);

		Scene scene = new Scene(pane,500,400);
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	
	public static void main(String[] args)
	{
		Application.launch(args);
	}
}
